# Maintainer: Simon Zeni <simon@bl4ckb0ne.ca>
pkgname=betula
pkgver=1.1.0
pkgrel=5
pkgdesc="free single-user bookmarking software"
url="https://betula.mycorrhiza.wiki/"
arch="all"
license="AGPL-3.0-only"
options="net" # go modules
makedepends="go sqlite-dev"
checkdepends="curl"
subpackages="$pkgname-openrc"
install="$pkgname.pre-install"
builddir="$srcdir/$pkgname-v$pkgver"
source="$pkgname-v$pkgver.tar.gz::https://git.sr.ht/~bouncepaw/betula/archive/v$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"
export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export CGO_ENABLED=1

build() {
	go mod tidy
	go build -o betula ./cmd/betula
}

check() {
	./test-web.sh
	local ret=$?

	# Cleanup so we don't hang CI
	killall -q betula
	return $ret
}

package() {
	install -Dm755 betula "$pkgdir"/usr/bin/betula

	install -Dm755 "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname

}
sha512sums="
812c228d4d99b21637c28513b3b09cc9357ea6b9bc9b2a5d17b40b06d5cb714992d1690177047a3b2460f605fa376c68baa2d9ea3131d1ff12cbb9c4bfc3060b  betula-v1.1.0.tar.gz
93b8c65542050a04c225dbbf375dc5b1c44ac21f49c03976745d76e6d8f3b2cc4b66151324cf7e60d7fe5737c7f6b054798d7f5aa01de1eea86ba7e3002929fa  betula.initd
9d45d9b2b67248ec1cf7736453af1c54da3ddb82b1f37df2046e45603db90ee4654f23b7c5d40e702a3ae56f9a800ddc051369dbf5082e86580ab625208f595e  betula.confd
"
